*Recoding ZA3065 

use "Data\ZA3065\ZA3065_v3-0-0.dta" , clear

*Support for democracy
 *not asked
 
*Support for liberal democracy
gen $libdem_opposition			= v170k
gen $libdem_freeopinion			= v170h
gen $libdem_conflict			= v170c							

*define missing values
mvdecode $libdem_opposition $libdem_freeopinion $libdem_conflict, ///
	mv(9=.a\8=.b)  //.a = no answer; .b= = don't know)

*Standardize range from 0 to 1; higher values indicate higher support for democracy
*reverse scale if necessary and standardize

foreach var of varlist $libdem_opposition $libdem_freeopinion {
	replace `var'	= (`var'-1)/4 if !missing(`var')
}

replace $libdem_conflict	= (5-$libdem_conflict)/4 if !missing($libdem_conflict)
	
*Sociodemographic Controls
gen			$gender 			= vsex-1

gen		 	$age				= 1994-vjahr							  	//survey year - year of birth	

gen 		$education			= vbildg
*define missing values
mvdecode	$education, mv(9=.a\8=.b)  //.a = no answer; .b = don't know
replace 	$education 			= 0 if $education 	<= 2 & !missing($education)  	//  Hautpschule, Mittlere Reife, = 0
replace 	$education 			= 1 if $education 	>= 3  & !missing($education) 	// Abitur/EOS; university degree = 1

gen 		$eastwest 			= vsplitwo-1

*Weight
*Repräsentativgewichte für gesamtdeutsche Analysen (mit Ost-West-Gewicht) Vorwahl oder Nachwahl: vgvwnwow
*Repräsentativgewichte für getrennte Ost-West-Analysen: Vorwahl oder Nachwahl: vgvwnw
gen weight = vgvwnwow

*Party ID
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyid_category		= 1 	if inlist(vpid, 1, 2, 4)
replace $partyid_category	= 0 	if inlist(vpid, 3, 5, 7)
replace $partyid_category	= -1 	if inlist(vpid, 6, 9)


*Party Vote
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyvote_category		= 1 	if inlist(v70, 1, 3)
replace $partyvote_category	= 0 	if inlist(v70, 2, 4, 6)
replace $partyvote_category	= -1 	if inlist(v70, 5, 12)

*Meta variables
gen 		$dataset 					= "ZA3065"
gen 		$year 						= 1994

*check
tab $libdem_opposition v170k, m
tab $libdem_freeopinion v170h, m
tab $libdem_conflict v170c, m
tab $gender vsex, m
tab $age vjahr, m
tab $education vbildg, m
tab $eastwest vsplitwo, m

*Save recode dataset
keep $libdem_opposition	$libdem_freeopinion $libdem_conflict $gender $age 	 	///
	$education $eastwest $dataset $year  weight	$partyid_category	$partyvote_category	
save ZA3065_recoded.dta, replace
